<template>
  <div>
    <span>微信免登授权中，请稍候...</span>
  </div>
</template>

<script>
import {getUser} from '@/api/wx'
import { mapActions } from 'vuex'
export default {
  name: 'wx_login',
  data() {
    return {
      user:{}
    };
  },
  created() {
    this.getUser(this.$route.query.code)
  },
  methods: {
    ...mapActions({
      login: 'user/wx_login',
    }),
    getUser(code){
      getUser(code).then(res =>{
        this.user = res.userinfo
        this.loginStart()
      })
    },
    async loginStart() {
      this.isShow = false; // 通过验证后，需要手动隐藏模态框
      try {
        this.loading = true
        await this.login(this.user).catch(() => {})
        await this.$router.push("/index")
      } finally {
        this.loading = false
      }
    },
  }
};
</script>

<style></style>
